﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel.Composition;
using ScrumFactory.Composition.View;

namespace ScrumFactory.Tasks {
    /// <summary>
    /// Interaction logic for UserTasksSelector.xaml
    /// </summary>
    [Export]
    public partial class UserTasksSelector : Window, IDialogView {

        private object model;

        private double matrixM11;
        
        public UserTasksSelector() {
            InitializeComponent();
            Loaded += new RoutedEventHandler(UserTasksSelector_Loaded);
            taskList.MouseLeave += new MouseEventHandler(UserTasksSelector_MouseLeave);
        }

        private void UserTasksSelector_MouseLeave(object sender, MouseEventArgs e) {
            Hide();
        }

        private void UserTasksSelector_Loaded(object sender, RoutedEventArgs e) {
            PresentationSource source = PresentationSource.FromVisual(this);
            if (source == null)
                return;

            matrixM11 = source.CompositionTarget.TransformFromDevice.M11;
            SetPosition();
        }

        private void SetPosition() {
            Left = (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width * matrixM11) - Width;
            Top = (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height * matrixM11) - Height;
        }


        public new void Show() {
            if(Owner==null)
                Owner = Application.Current.MainWindow;
            SetPosition();
            base.Show();            
        }
        
        

        [Import(typeof(ViewModel.UserTasksSelectorViewModel))]
        public object Model {
            get {
                return model;
            }
            set {
                model = value;
                DataContext = model;
            }
        }

        
    }
}
